/**
 *
 *      ___                       ___
 *     /\  \          ___        /\  \
 *    /::\  \        /\  \      /::\  \
 *   /:/\:\  \       \:\  \    /:/\ \  \
 *  /:/  \:\  \      /::\__\  _\:\~\ \  \
 * /:/__/ \:\__\  __/:/\/__/ /\ \:\ \ \__\
 * \:\  \  \/__/ /\/:/  /    \:\ \:\ \/__/
 *  \:\  \       \::/__/      \:\ \:\__\
 *   \:\  \       \:\__\       \:\/:/  /
 *    \:\__\       \/__/        \::/  /
 *     \/__/                     \/__/
 *
 * CIS - Clang Indexing Service is a Project Manager & Source code indexing service
 * created so as to simplify the indexing of C/C++ based source code which use
 * standardized build mechanisms.
 *
 **/

#include "../includes/indexserverapplication.hxx"

#include <Poco/Logger.h>
#include <Poco/LogStream.h>

using namespace cis;

namespace {
Poco::Logger& logger = Poco::Logger::get("IndexServerApplication");
Poco::LogStream logstream(logger);
}

IndexServerApplication::IndexServerApplication()
{
    indexServerSubSys = new IndexServer();
    this->addSubsystem(indexServerSubSys);
}

IndexServerApplication::~IndexServerApplication()
{
}

int IndexServerApplication::main(const std::vector<std::string>& args)
{
    logstream << "IndexServerApplication Initialized!" << std::endl;
    this->waitForTerminationRequest();

    return 0;
}

void IndexServerApplication::defineOptions(Poco::Util::OptionSet& options)
{
    ServerApplication::defineOptions(options);
    options.addOption(Poco::Util::Option("config", "f", "configuration file", true, "configfile", true)
                      .repeatable(false)
                      .callback(Poco::Util::OptionCallback<IndexServerApplication > (
                                    this, &IndexServerApplication::handleConfigure)));

    options.addOption(
        Poco::Util::Option("help", "h", "display argument help information")
        .required(false)
        .repeatable(false)
        .callback(Poco::Util::OptionCallback<IndexServerApplication > (
                      this, &IndexServerApplication::handleHelp)));
}

void IndexServerApplication::handleHelp(const std::string&, const std::string&)
{
}

void IndexServerApplication::handleConfigure(const std::string& key, const std::string& filename)
{
    loadConfiguration(filename);
}